package com.ruoyi.restaurant.service.impl;

import java.util.List;

import com.ruoyi.restaurant.domain.RestDish;
import com.ruoyi.restaurant.service.IRestDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.restaurant.mapper.RestDishPurchaseMapper;
import com.ruoyi.restaurant.domain.RestDishPurchase;
import com.ruoyi.restaurant.service.IRestDishPurchaseService;

/**
 * 菜品采购Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-29
 */
@Service
public class RestDishPurchaseServiceImpl implements IRestDishPurchaseService 
{
    @Autowired
    private RestDishPurchaseMapper restDishPurchaseMapper;

    @Autowired
    private IRestDishService iRestDishService;

    /**
     * 查询菜品采购
     * 
     * @param id 菜品采购主键
     * @return 菜品采购
     */
    @Override
    public RestDishPurchase selectRestDishPurchaseById(Long id)
    {
        return restDishPurchaseMapper.selectRestDishPurchaseById(id);
    }

    /**
     * 查询菜品采购列表
     * 
     * @param restDishPurchase 菜品采购
     * @return 菜品采购
     */
    @Override
    public List<RestDishPurchase> selectRestDishPurchaseList(RestDishPurchase restDishPurchase)
    {
        
        return restDishPurchaseMapper.selectRestDishPurchaseList(restDishPurchase);
    }

    /**
     * 新增菜品采购
     * 
     * @param restDishPurchase 菜品采购
     * @return 结果
     */
    @Override
    public int insertRestDishPurchase(RestDishPurchase restDishPurchase)
    {
        Long dishId = restDishPurchase.getDishId();
        RestDish restDish = iRestDishService.selectRestDishById(dishId);
        restDish.setStock(restDish.getStock() + restDishPurchase.getQuantity());
        iRestDishService.updateRestDish(restDish);
        return restDishPurchaseMapper.insertRestDishPurchase(restDishPurchase);
    }

    /**
     * 修改菜品采购
     * 
     * @param restDishPurchase 菜品采购
     * @return 结果
     */
    @Override
    public int updateRestDishPurchase(RestDishPurchase restDishPurchase)
    {
        return restDishPurchaseMapper.updateRestDishPurchase(restDishPurchase);
    }

    /**
     * 批量删除菜品采购
     * 
     * @param ids 需要删除的菜品采购主键
     * @return 结果
     */
    @Override
    public int deleteRestDishPurchaseByIds(Long[] ids)
    {
        return restDishPurchaseMapper.deleteRestDishPurchaseByIds(ids);
    }

    /**
     * 删除菜品采购信息
     * 
     * @param id 菜品采购主键
     * @return 结果
     */
    @Override
    public int deleteRestDishPurchaseById(Long id)
    {
        return restDishPurchaseMapper.deleteRestDishPurchaseById(id);
    }
}
